CMAKE_MINIMUM_REQUIRED (VERSION 3.10)

SET ( RBDL_LUAMODEL_TESTS_VERSION_MAJOR 1 )
SET ( RBDL_LUAMODEL_TESTS_VERSION_MINOR 0 )
SET ( RBDL_LUAMODEL_TESTS_VERSION_PATCH 0 )

SET ( RBDL_LUAMODEL_TESTS_VERSION 
	${RBDL_LUAMODEL_TESTS_VERSION_MAJOR}.${RBDL_LUAMODEL_TESTS_VERSION_MINOR}.${RBDL_LUAMODEL_TESTS_VERSION_PATCH}
)


PROJECT (RBDL_LUAMODEL_TESTS VERSION ${RBDL_LUAMODEL_TESTS_VERSION})

# Look for catch2
FIND_PACKAGE(Catch2 3 REQUIRED)
FIND_PACKAGE (Lua51 REQUIRED)
INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}/include
                     ${LUA_INCLUDE_DIR}
                     ${CMAKE_SOURCE_DIR}/tests
                     ../)
# on unix systems add /usr/local/include to include dirs
# this was added since macos homebrew installs many things there but macos
# does not automatically search their, and on linux systems this does not hurt
IF (NOT WIN32)
  INCLUDE_DIRECTORIES(/usr/local/include)
ENDIF (NOT WIN32)

SET ( LUAMODEL_TESTS_SRCS
	testLuaModel.cc
	 ../luamodel.h
	 ../luatables.h	
	../luamodel.cc
	../luatables.cc
	)

IF ( ${CMAKE_VERSION} VERSION_LESS 3.12.0 )
  ADD_DEFINITIONS (-DRBDL_LUAMODEL_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/..")
ELSE( ${CMAKE_VERSION} VERSION_LESS 3.12.0 )
  ADD_COMPILE_DEFINITIONS (RBDL_LUAMODEL_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/..")
ENDIF( ${CMAKE_VERSION} VERSION_LESS 3.12.0 )

SET_TARGET_PROPERTIES ( ${PROJECT_EXECUTABLES} PROPERTIES
  LINKER_LANGUAGE CXX
)

ADD_EXECUTABLE ( rbdl_luamodel_tests ${LUAMODEL_TESTS_SRCS} )

SET_TARGET_PROPERTIES ( rbdl_luamodel_tests PROPERTIES
	LINKER_LANGUAGE CXX
	OUTPUT_NAME luamodel_tests
	)

SET (RBDL_LIBRARY rbdl)
IF (RBDL_BUILD_STATIC)
	SET (RBDL_LIBRARY rbdl-static)
ENDIF (RBDL_BUILD_STATIC)

SET (MUSCLE_ADDON_LIBRARY rbdl_muscle)
IF (RBDL_BUILD_STATIC)
	SET (MUSCLE_ADDON_LIBRARY rbdl_muscle-static)
ENDIF (RBDL_BUILD_STATIC)


IF(RBDL_BUILD_ADDON_MUSCLE)
	TARGET_LINK_LIBRARIES ( rbdl_luamodel_tests
      Catch2::Catch2WithMain
			${MUSCLE_ADDON_LIBRARY}
			${RBDL_LIBRARY}
			${LUA_LIBRARIES}
		)
ELSE(RBDL_BUILD_ADDON_MUSCLE)
	TARGET_LINK_LIBRARIES ( rbdl_luamodel_tests
			${RBDL_LIBRARY}
			${LUA_LIBRARIES}
      Catch2::Catch2WithMain
		)
ENDIF(RBDL_BUILD_ADDON_MUSCLE)
	
OPTION (RUN_AUTOMATIC_TESTS "Perform automatic tests after compilation?" OFF)

IF (RUN_AUTOMATIC_TESTS)

ADD_CUSTOM_COMMAND (TARGET rbdl_luamodel_tests
	POST_BUILD
	COMMAND ./luamodel_tests
	COMMENT "Running automated addon luamodel tests..."
	)
ENDIF (RUN_AUTOMATIC_TESTS)
